<template>
  <div class="home-singer">
    <h3>热门歌手</h3>
    <div class="wrapper" ref="wrapper">
      <ul class="content" ref="content">
        <li v-for="(item, index) in listData" :key="index" @click="selectItem(item)">
          <div class="cover">
            <van-image :src="item.picUrl" style="width: 150px;height:122px" radius="1rem"></van-image>
          </div>
          <span>{{ item.name }}</span>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
//import axios from 'axios'
import {betterScrollHorizontal} from '../../common/betterScroll.js'
export default {
  data() {
    return {
      listData: []
    }
  },
  created() {
    this.getSingerListData()
  },
  methods: {
    getSingerListData() {
      this.$request('get', '/toplist/artist')
        // this.$request('get', '/recommend/playlist/u')
        .then(code => {
          console.log(code)
          this.listData = code.list.artists
          
          //console.log(this.listData)
          betterScrollHorizontal(
            this,
            this.$refs.wrapper,
            this.$refs.content,
            this.listData.length,
            10
          )
        })
    },
    selectItem(item){
      const id = item.id
      console.log(id)
      this.$router.push({path:`/singsong/${id}`})
    }
  },
}
</script>
    
<style scoped>
/* .home-recommond > ul {
  display: flex;
  flex-wrap: wrap;
}
.home-recommond > ul > li {
  width: calc((100% - 1rem) / 3 * 1);
}
.home-recommond > ul > li:nth-of-type(3n + 2) {
  margin-left: 0.5rem;
  margin-right: 0.5rem;
} */
.cover {
  position: relative;
}

.wrapper {
  width: 100%;
  /* 容器的宽度就是屏幕的宽度 */
  overflow: hidden;
}

/* content内容区的宽度要大于wrapper容器的宽度，12个列表项 */
/* ul.content {
  width: calc(100 * 10rem);
  width: calc(12 * 10rem);
} */

ul.content li {
  /**li默认是块级元素，修改为行内元素，但是要具备块级元素的特性*/
  display: inline-block;
  width: 10rem;
  vertical-align: top;
}

ul.content li * {
  margin: 0 0.1rem;
  /*里面的元素与li的边缘有个间距*/
}


ul.content>li>span {
  font-size: 0.8rem;
  color: #625858;
}
</style>